namespace org.jawk.jrt
{
	/// <summary>
	/// Similar to StringTokenizer, except that tokens are delimited
	/// by a single character.
	/// </summary>
	/// <remarks>
	/// Similar to StringTokenizer, except that tokens are delimited
	/// by a single character.
	/// </remarks>
	public class SingleCharacterTokenizer : java.util.IEnumeration<object>
	{
		private string input;

		private int split_char;

		private int idx = 0;

		/// <summary>Construct a RegexTokenizer.</summary>
		/// <remarks>Construct a RegexTokenizer.</remarks>
		/// <param name="input">The input string to tokenize.</param>
		/// <param name="split_char">
		/// The character which deliniates tokens
		/// within the input string.
		/// </param>
		public SingleCharacterTokenizer(string input, int split_char)
		{
			// input + sentinel
			this.input = input + ((char)split_char);
			this.split_char = split_char;
		}

		// to satisfy the Enumeration<Object> interface
		public virtual bool HasMoreElements()
		{
			return idx < input.Length;
		}

		private System.Text.StringBuilder sb = new System.Text.StringBuilder();

        public virtual object NextElement()
        {
            sb.Length = 0;
            while (idx < input.Length)
            {
                if (input[idx] == split_char)
                {
                    ++idx;
                    break;
                }
                else
                {
                    sb.Append(input[idx++]);
                }
            }
            return sb.ToString();
        }
    }
}
